using System;
using System.Text;
using AndyPike.Presentations.IntroToTDD.Interfaces;

namespace AndyPike.Presentations.IntroToTDD
{
    public class StringReverserUsingStringBuilder : IReverser<string>
    {
        private readonly ILogger logger;

        public StringReverserUsingStringBuilder(ILogger logger)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");

            this.logger = logger;
        }
        
        public string Reverse(string input)
        {
            if(input == null)
                throw new ArgumentNullException("input");

            var output = new StringBuilder();

            for(int x = input.Length - 1; x >= 0; x--)
            {
                output.Append(input[x]);
            }

            logger.Info(string.Format("The string '{0}' was reversed to '{1}'.", input, output));

            return output.ToString();
        }
    }
}